home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Environments / Chipmunk Basic 3.5.2 / boxes.bas < prev    next >
BASIC Source File  |  1996-07-27  |  2KB  |  62 lines

  1. 100 rem ** A Demo of 3 sprites bouncing around over a changing background **
  2. 110 rem
  3. 120 dim x(10),y(10),dx(10),dy(10)
  4. 150 gosub 340
  5. 155 print " boxes and sprites ";time$
  6. 160 for i2 = 1 to 600000
  7. 170 x1 = x(4)+rnd(320)
  8. 180 x2 = x(4)+rnd(320)
  9. 190 if (x1 > x2) then 170
  10. 200 y1 = y(4)+rnd(240)
  11. 210 y2 = y(4)+rnd(240)
  12. 220 if (y1 > y2) then 200
  13. 230 m = rnd(32)
  14. 240 j = rnd(100) : j2 = rnd(100) : j3 = rnd(100)
  15. 250 graphics color j,j2,j3
  16. 260 if rnd(10) > 6 then goto 290
  17. 270 graphics fillrect x1,y1,x2,y2,m : graphics rect x1,y1,x2,y2
  18. 280 goto 300
  19. 290 graphics filloval x1,y1,x2,y2,m : graphics oval x1,y1,x2,y2
  20. 300 if i2 and 1 then gosub 450
  21. 310 graphics(0) : rem *** wait for refresh ***
  22. 320 next i2
  23. 330 end
  24. 340 rem *** display an initial background ***
  25. 350 cls
  26. 360 graphics 0
  27. 370 for i = 1 to 20
  28. 380 moveto 10,10*i : lineto 200,10*i
  29. 390 moveto 10*i,10 : lineto 10*i,200
  30. 400 next i
  31. 410 t = timer
  32. 420 moveto 210,100 : graphics drawtext "Demo"
  33. 430 for i = 1 to 10 : x(i) = 100+i : y(i) = 100-i : next i
  34. 440 return
  35. 450 rem *** Display and Move Sprites ***
  36. 460 sprite 1 x(1),y(1),131
  37. 470 sprite 2 x(2),y(2),128
  38. 480 sprite 3 x(3),y(3),129
  39. 485 graphics window -1,-1,x(4),y(4),2
  40. 490 for i = 1 to 4
  41. 500 dx(i) = dx(i)-1+rnd(3)
  42. 510 if abs(dx(i)) > 10 then dx(i) = dx(i)/2
  43. 520 x(i) = x(i)+dx(i)
  44. 530 if x(i) > 310 or x(i) < 8
  45. 532   dx(i) = sgn(100-x(i))*abs(dx(i)) : x(i) = x(i)+2*dx(i)
  46. 534   if i < 4 then sound 400,0.05,40
  47. 536 endif
  48. 540 dy(i) = dy(i)-1+rnd(3)
  49. 550 if abs(dy(i)) > 10 then dy(i) = dy(i)/2
  50. 560 y(i) = y(i)+dy(i)
  51. 570 if y(i) > 220 or y(i) < 8
  52. 572   dy(i) = sgn(100-y(i))*abs(dy(i)) : y(i) = y(i)+2*dy(i)
  53. 574   if i < 4 then sound 400,0.05,40
  54. 576 endif
  55. 580 next i
  56. 582 if x(4) > graphics(-38)-320 then x(4) = graphics(-38)-322
  57. 584 if y(4) > graphics(-39)-240 then y(4) = graphics(-39)-242
  58. 590 n = n+1
  59. 600 if timer-t > 10 then print (n-n0)/(timer-t);" fps",fre : t = timer : n0 = n
  60. 610 return
  61. 620 end
  62.